package com.foreknow.demo4;

import java.util.Scanner;

public class Bank {
    public static void welcome(){//欢迎界面
        System.out.println("--------------------------");
        System.out.println("****** 欢迎登陆 ******");
        System.out.println("****** 中国银行 ******");
        System.out.println("****** 1.0版本 ******");
        System.out.println("--------------------------");
    }
    public static boolean login(String username,String password){
        Scanner input = new Scanner(System.in);
        boolean denglu = false;
        for (int i = 100;i <= 102;i++ ){
            System.out.println("请输入用户名:  ");
            String account = input.next();
            System.out.println("请输入密码:  ");
            String mima = input.next();
            if (account.equals(username) && password.equals(mima)){
                denglu = true;
                break;
            }else{
                if (i<102){
                    System.out.println("密码错误还有"+(102-i)+"次机会");
                }else{
                    System.out.println("错误三次锁卡");
                }
            }

        }
        return denglu;

    }
    public static void decide(){
        Scanner input = new Scanner(System.in);
        System.out.println("是否继续操作(y/n)");
        String xz = input.next();
        if (xz.equals("y")){

        }else if(xz.equals("n")){
            System.exit(0);
        }else{
            System.out.println("输入错误重新输入");
        }
    }
    public static void checkmoney(double money){
        System.out.println(money);
    }
    public static double setmoney(double money){
        Scanner input = new Scanner(System.in);
        System.out.println("输入存款金额： ");
        double setmoney = input.nextDouble();

        if (setmoney > 10000){
            System.out.println("存款金额不能大于10000");
        }else if (setmoney < 0 ){
            System.out.println("存款金额大于0");
        }else if (setmoney %100 != 0){
            System.out.println("必须是100的整数");
        }else {
            money += setmoney;
            System.out.println(money);
        } return money;
    }
    public static double getmoney (double money){
        Scanner input = new Scanner(System.in);
        System.out.println("输入取款金额： ");
        double getmoney = input.nextDouble();
        if (getmoney > money){
            System.out.println("金额不足");
            getmoney = 0;
        }else if (getmoney > 3000 ){
            System.out.println("取款金额超过3000");
            getmoney = 0;
        }else if (getmoney %100 != 0){
            System.out.println("必须是100的整数");
            getmoney = 0;
        }else if(getmoney < 0){
            System.out.println("取款金额小于0");
            getmoney = 0;
        } else {
            money -= getmoney;
        }return money;
    }
    public static String changepwd(String password){
        Scanner input = new Scanner(System.in);
        String date = password;
        System.out.println("输入旧密码：");
        String oldpassword = input.next();
        if (oldpassword.equals(password)){
            System.out.println("请输入新密码：");
            String newpassword = input.next();
            System.out.println("请再次输入新密码：");
            String newpasswrd1 = input.next();
            if (newpassword.equals(newpasswrd1)){
                date = newpassword;
            } else {
                System.out.println("两次密码输入不一致");
            }
        } else {
            System.out.println("旧密码输入错误");
        } return date;
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String username = "admin";
        String password = "123456";
        double money = 10000;
        welcome();
        boolean b = login(username,password);
        while (b){
            while (true){
                System.out.println("1.查询余额 2.存款 3.取款 4.修改密码 5.退出");
                int Interface = input.nextInt();
                switch (Interface){
                    case 1:
                        checkmoney(money);
                        decide();
                        break;
                    case 2:
                        money = setmoney(money);
                        decide();
                        break;
                    case 3:
                        money = getmoney(money);
                        System.out.println(money);
                        decide();
                        break;
                    case 4:
                        password = changepwd(password);
                        System.out.println("当前密码"+password);
                        decide();
                        break;
                    case 5:
                        System.exit(0);
            }

            }
        }
    }
}
